package com.hejx.web.controller;

import com.hejx.dto.OnlineUser;
import com.hejx.model.Role;
import com.hejx.web.annotation.hasRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * Created by 追风少年
 *
 * @email doubihah@foxmail.com
 * @create 2018/1/4 14:02
 **/
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {

    @RequestMapping("/hello.json")
    @ResponseBody
    public String hello(){
        log.info("杜鹃杜鹃杜鹃杜鹃");
        return "hello world222";
    }

    @RequestMapping("/login")
    @ResponseBody
    public String login(HttpSession session){
        ArrayList<Role> roles = new ArrayList<>();
        Role role = new Role();
        role.setId(2L);
        role.setRole("admin2222");
        roles.add(role);
        session.setAttribute("user",new OnlineUser("testUser1",roles,null));
        return "登录成功";
    }

    @RequestMapping("/index.html")
    public String index(){
        return "index";
    }

    @RequestMapping("/auth")
    @ResponseBody
    @hasRole("admin222")
    public String auth(){
        return "auth.json";
    }

    @RequestMapping("/{area}.html")
    public String jump(@PathVariable String area){
        return area;
    }

}
